package com.community.demo.service.impl;

import com.community.demo.dao.GoodsRepository;
import com.community.demo.domain.Goods;
import com.community.demo.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    private GoodsRepository goodsRepository;

    @Override
    public List<Goods> getAllGoods(){
        return goodsRepository.findAll();
    }

    @Override
    public void saveAndFlush(Goods goods) {
        goodsRepository.saveAndFlush(goods);
    }

    @Override
    public void deleteGoods(long id) {
        Goods goods = goodsRepository.findById(id).get();
        goods.setFlag(false);
        goodsRepository.saveAndFlush(goods);
    }

    @Override
    public Goods findGoodsById(long id) {
        return goodsRepository.findById(id).get();
    }
}
